<?php

namespace App\Schema;
use App\Model\Permission\Role;
use Carbon\CarbonInterface;
use Hyperf\Swagger\Annotation\Property;
use Hyperf\Swagger\Annotation\Schema;

#[Schema(title: 'TopicSchema')]
final class TopicSchema implements \JsonSerializable
{
    #[Property(property: 'id', title: '主键', type: 'int')]
    public ?int $id;

    #[Property(property: 'details_id', title: 'details_id', type: 'string')]
    public ?string $details_id;

    #[Property(property: 'format', title: 'format', type: 'string')]
    public ?string $format;

    #[Property(property: 'type', title: 'type', type: 'int')]
    public ?int $type;

    #[Property(property: 'title', title: 'title', type: 'string')]
    public ?string $title;

    #[Property(property: 'title_img', title: 'title_img', type: 'string')]
    public ?string $title_img;

    #[Property(property: 'details', title: 'details', type: 'string')]
    public ?int $details;


    #[Property(property: 'created_at', title: '', type: 'string')]
    public mixed $createdAt;

    #[Property(property: 'updated_at', title: '', type: 'string')]
    public string $updatedAt;

    public function __construct(Role $model)
    {
        $this->id = $model->id;
        $this->details_id = $model->details_id;
        $this->format = $model->format;
        $this->type = $model->type;
        $this->title = $model->title;
        $this->title_img = $model->title_img;
        $this->details = $model->details;
        $this->createdAt = $model->created_at;
        $this->updatedAt = $model->updated_at->format(CarbonInterface::DEFAULT_TO_STRING_FORMAT);
    }

    public function jsonSerialize(): mixed
    {
        return ['id' => $this->id, 'details_id' => $this->details_id, 'format' => $this->format, 'type' => $this->type, 'title' => $this->title, 'title_img' => $this->title_img, 'details' => $this->details, 'created_at' => $this->createdAt, 'updated_at' => $this->updatedAt];
    }
}